package com.xyhy.starter.file.oss;

import io.swagger.annotations.ApiModelProperty;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import com.xyhy.core.base.Strings;
import com.xyhy.core.file.oss.OssConstants;

@Getter
@Setter
@ConfigurationProperties(prefix = "tools.oss.aliyun")
public class AliyunOssProperties {

  private String bucket;

  private String endpoint;

  private String accessKey;

  private String accessSecret;

  @ApiModelProperty("文件存放路径，默认为 media/yyyyMMdd")
  private String pathParent;

  @ApiModelProperty("办事指南文件存放路径，默认为 media/yyyyMMdd")
  private String filesPath;

  @ApiModelProperty("绑定的域名")
  private String bindDomain;

  @ApiModelProperty("回调基本地址，如 https://xyhy.com")
  private String callbackBaseUrl = Strings.EMPTY;

  @Value("${server.servlet.context-path}")
  @Setter(AccessLevel.NONE)
  private String servletContextPath;

  @ApiModelProperty("oss渠道id，计算字段，无法set")
  @Setter(AccessLevel.NONE)
  private Long channelId;

  @ApiModelProperty("回调地址")
  public String getCallbackUrl() {
    return String.format("%s%s/%s", this.callbackBaseUrl, this.servletContextPath, OssConstants.CALLBACK_URL.ALIYUN);
  }

}
